<template>
	<view class="main">
		<u-navbar :is-back="true" title="物业报修" :background="background" title-size="32" title-color="#000"  :border-bottom="false" ></u-navbar>
		<view class="content">
			<view class="top">
				<text>类目选择</text>
				<view class="select" @click="select(1)">
					<text>{{types==''?'请选择保修的物品':types.label}}</text>
					<image src="../../static/images/right.png" mode=""></image>
				</view>
			</view>
			<view class="top">
				<text>联系电话</text>
				<view class="select">
					<input type="number" placeholder="请输入手机号" maxlength="11" v-model="phone" />
				</view>
			</view>
			<view class="top">
				<text>楼牌号</text>
				<view class="select">
					<text v-if="build==''||unit==''||number==''" @click="select(2)">请选择楼牌号</text>
					<text v-else @click="select(2)">
						<text v-for="(item,index) in arr " :key="index">{{item.label}}</text>
					</text>
				</view>
			</view>
			<view class="question">
				<view class="titles">
					问题描述
				</view>
				<textarea maxlength="-1" placeholder="请输入问题描述" v-model="question" />
			</view>
		</view>
		<view class="button" @click="repair">
			提交
		</view>
		<u-select v-model="show" :list="list" @confirm="confirm"></u-select>
		<u-select v-model="show2" mode="mutil-column-auto" :list="buildinglist" @confirm="confirm2"></u-select>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				arr: [],
				types: [],
				show: false,
				phone: '',
				buildinglist: [],
				question: '',
				show2: false,
				list: [{
					label: '',
					value: ''
				}],
				build: '', //楼
				unit: '',
				number: '',
			}
		},
		onLoad() {
			this.address()
			this.repairtype()
		},
		onShow() {},
		methods: {
			select(index) {
				if (index == 1) {
					this.show = true
				} else if (index == 2) {
					this.show2 = true
				}
			},
			confirm(e) {
				console.log(e);
				console.log(e[0].value);
				console.log(e[0].label);
				this.types = e[0]
				console.log(this.types);
			},
			confirm2(e) {
				console.log(e);
				this.arr = e
				this.build = e[0].value
				this.unit = e[1].value
				this.number = e[2].value
			},
			repairtype() {
				global.$http.request({
					url: '/system/dict/data/type/' + 'repair_category',
					method: 'GET',
					header: {
						'Authorization': uni.getStorageSync('token') //自定义请求头信息
					},
					data: {}
				}).then(res => {
					console.log('类型',res.data.data);
					if (res.data.code == 200) {
						var that = this
						that.list = res.data.data
						for (let i = 0; i < that.list.length; i++) {
							that.list[i].label = res.data.data[i].dictLabel
							that.list[i].value = res.data.data[i].dictValue
						}
					}
				})
			},
			repair() {
				if (this.types == '' || this.phone == '' || this.build == '' || this.unit == '' || this.number == '' ||
					this.question == '') {
					uni.showToast({
						title: '请将信息填写完整',
						icon: "none",
						mask: true,
						duration: 1000
					})
				} else {
					global.$http.request({
						url: '/business/repair',
						header: {
							'Authorization': uni.getStorageSync('token') //自定义请求头信息
						},
						data: {
							repairCategory: this.types.value,
							problemDescription: this.question,
							contactNumber: this.phone,
							repairFloor: this.build,
							repairUnit: this.unit,
							repairRoom: this.number,
						},
					}).then(res => {
						if (res.data.code == 200) {
							uni.showToast({
								title: res.data.msg,
								icon: "none",
								mask: true,
								duration: 1000
							})
						}
					})
				}
			},
			address() {
				global.$http.request({
					url: '/business/untoken/getBuildCascade',
					method: 'GET',
					data: {},
				}).then(res => {
					console.log(res.data.data);
					this.buildinglist = res.data.data
					console.log('楼牌号', this.buildinglist);
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		font-family: PingFang SC;
		background-color: #f7f7f7;

		.main {
			width: 750rpx;

			.content {
				.top {
					margin: 2rpx 0;
					background-color: #fff;
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 31rpx 30rpx 31rpx 37rpx;

					.select {
						display: flex;
						align-items: center;

						text {
							font-size: 28rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #074D93;
							padding-right: 23rpx;
						}

						image {
							width: 8rpx;
							height: 14rpx;
						}

						input {
							width: 200rpx;
							// text-align: right;
							font-size: 28rpx;
						}
					}
				}

				.question {
					margin-top: 10rpx;
					background-color: #fff;
					padding: 30rpx 38rpx;

					.titles {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #000000;
						padding-bottom: 30rpx;
						border-bottom: 1rpx solid #f7f7f7;
					}

					textarea {
						padding-top: 25rpx;
						font-size: 26rpx;
					}
				}
			}

			.button {
				width: 540rpx;
				margin: 365rpx auto 0 auto;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				background: #074D93;
				border-radius: 40rpx;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
			}
		}
	}
</style>
